package com.weimob.mcloud.wechatwork.customer.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {

    public static final String SHORT_FORMAT = "yyyyMMdd";

    //将字符串时间格式转为long形
    public static Long getToLong(String DateTime){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date time = sdf.parse(DateTime);
            return time.getTime();
        } catch (Exception e) {

        }
        return null;
    }

    /**
     * 获取今日字符串
     * @return
     */
    public static String getTodayDate() {
        Date now = new Date();
        DateFormat dateFormat = new SimpleDateFormat(SHORT_FORMAT);
        return dateFormat.format(now);
    }

    /**
     * date转年月日子串
     * @param date
     * @return
     */
    public static String getDateStr(Date date){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.format(date);
        } catch (Exception e) {

        }
        return null;
    }

    /**
     * date转年月日时分秒
     * @param date
     * @return
     */
    public static String getDateTimeStr(Date date){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.format(date);
        } catch (Exception e) {

        }
        return null;
    }
}
